<script setup lang="ts">
import { ref } from 'vue'
import { get } from '@/utils/service'
import { VUE_APP_BASE_API } from '@/utils/baseConfig'
import { showFailToast } from 'vant'
const showSignDialog = ref(false)
const myRewardStaticView = ref({})
const enterpriseBaseSet = ref({})
const agentRule = ref("");
queryMyRewardTotalWechat()
function onClickLeft() {
  window.history.back()
}
function queryMyRewardTotalWechat() {
  get('/rewardWechatNew/queryMyRewardTotalWechat', {}).then((res) => {
    if (res.code == 0) {
      myRewardStaticView.value = res.data
    }
  })
}
const rewardLists = ref([])
const loading = ref(false)
const finished = ref(false)
const noEmpty = ref(false)

const page = ref(1)
const limit = 10
function onLoad() {
  queryData()
}
queryEnterpriseSetMember();
function queryEnterpriseSetMember() {
  get('/enterpriseBaseSetWechatNew/queryWechat', {}).then((res) => {
    if (res.code == 0) {
       enterpriseBaseSet.value = res.data
      agentRule.value=VUE_APP_BASE_API+enterpriseBaseSet.value.agentRoleDesImage
    } else {
      showFailToast('无会员信息')
    }
  })
}
function queryData() {
  // 异步更新数据
  // setTimeout 仅做示例，真实场景中一般为 ajax 请求
  get('/rewardWechatNew/queryMyRewardWechat', {
    limit: limit,
    page: page.value,
  })
    .then((res) => {
      console.log(1)
      if (res.code === 0) {
        // 正常返回数据
        loading.value = false
        noEmpty.value = false
        res.data.forEach((item) => {
          rewardLists.value.push({
            ...item,
          })
        })
        if (page.value == res.totalPage) {
          loading.value = true
          finished.value = true
          noEmpty.value = false
        } else {
          page.value++
        }
      } else {
        //其他返回数据情况
        if (res.count > 0) {
          //有数据情况
          if (res.code == 201) {
            loading.value = true
            finished.value = true
            noEmpty.value = false
          }
        } else {
          //无数据情况
          loading.value = true
          finished.value = true
          noEmpty.value = true
        }
      }
    })
    .catch((err) => {
      console.log(err)
    })
}
</script>
<template>
  <van-nav-bar title="我的佣金" left-text="返回" left-arrow @click-left="onClickLeft" />
  <div class="myPointDes">
    <div class="myRewardHeader">
      <div>
        <h2 style="">
          本月收益:<span>{{ myRewardStaticView.monthTotal }}</span
          >元
        </h2>
      </div>
      <div>
        <h2 style="">
          累计收益:<span>{{ myRewardStaticView.allTotal }}</span
          >元
        </h2>
      </div>
    </div>
    <p class="roleRule" @click="showSignDialog = true">推荐规则?</p>
  </div>
  <div class="itemContent">
    <van-empty
        v-if="noEmpty == true"
        :image="VUE_APP_BASE_API+'/images/vue/noData.png'"
        image-size="100"
        description="暂无数据"
      />

      <van-list
        v-else
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div class="rewardItemItem" v-for="reward in rewardLists" :key="reward.dbid">
          <div class="rewardContentItem">
            <div class="leftText">
              <h2>{{ reward.rewardFrom }}</h2>
              <div style="">{{ reward.createTime }}</div>
            </div>
            <div>
              <div class="rightNum">
                {{ reward.rewardMoney }}
              </div>
            </div>
          </div>
          <div class="rewardDes">{{reward.note  }}</div>
        </div>
        <br />
      </van-list>
      <div style="clear: both;"></div>
  </div>
  <br />
  <van-popup closeable v-model:show="showSignDialog" position="bottom" round :style="{height: '80%'}">
    <div class="mainContent">
      <img :src="agentRule" style="padding: 40px 12px;width: 100%;border-radius: 12px;"></img>
    </div>
  </van-popup>
</template>
